<?php

jimport('joomla.application.component.controller');

class KontaktController extends JController
{
    /**
     * Method to display the view
     *
     * @access    public
     */
    function display()
    {
        //parent::display();
		
		$vLayout = JRequest::getCmd( 'layout', 'default' );
		$vName = JRequest::getCmd( 'view', 'index' );
		$mName = JRequest::getCmd( 'model', 'kontakt' );
		
		$document = &JFactory::getDocument();
		$vType = $document->getType();

		// Get/Create the view
		$view = &$this->getView( $vName, $vType);

		// Get/Create the model
		if ($mName && $model = &$this->getModel($mName)) {
			// Push the model into the view (as default)
			$view->setModel($model, true);
		}
		
		// message		
		/*global $mainframe, $option;
		$msg = $mainframe->getUserState( $option.'msg' );
		$mainframe->setUserState( $option.'msg', '' );
		$view->assignRef( 'msg', $msg );*/

		// Set the layout
		$view->setLayout($vLayout);

		// Display the view
		$view->display();
    }
	
	function submit()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
		
		$post	= JRequest::get('post');
		
		$name		= JRequest::getVar( 'name',			'',			'post' );
		$email		= JRequest::getVar( 'email',		'',			'post' );		
		$subject	= JRequest::getVar( 'subject',		'',			'post' );
		$message	= JRequest::getVar( 'message',		'',			'post' );
		
//		$subject	= 'LA Taskeholder - Besked fra kontakt-formularen';
//		$body = "Hej Admin!\n\r\n\rDer er en forespørgsel fra kontakt-formularen fra lataskeholder.dk\nNavn: $name\nAdresse: $address\nEmail: $email\nTelefon: $telefon\nBesked: $text\n\r\n\rMed venlig hilsen,\nLA Accessories Team";
				
		jimport('joomla.mail.helper');
		$mail = JFactory::getMailer();

//		$component_params = &JComponentHelper::getParams('com_contact');
		$config = JFactory::getConfig()->toArray();
		
		$mail->addRecipient( $config['mailfrom'] );
		$mail->setSender( array( $email, $name ) );
		$mail->setSubject( $subject );
		$mail->setBody( $message );

		$sent = $mail->Send();
		
		// message
		$msg = JText::_( 'Submit' );

		/*global $mainframe, $option;
		$mainframe->setUserState( $option.'msg', $msg  );*/

		$link = JRoute::_('index.php?option=com_kontakt&view=index&layout=response');
		$this->setRedirect($link, $msg);
	}
}
?> 